package com.n9.buymsg.service.qqonline.converter;

import com.n9.sdk.model.PurchaseMessage;

import java.util.Objects;

/**
 * 消息类型过滤器
 * @Author: ice
 * @Date: 2020-07-06 9:07
 */
public class MsgTypeFilter implements PurchaseMessageFilter {
    private String[] msgTypes;//消息类型

    public MsgTypeFilter(String[] msgTypes) {
        this.msgTypes = msgTypes;
    }

    @Override
    public void init() {
    }

    @Override
    public void doFilter(PurchaseMessage purchaseMessage, FilterChain chain) {
        //不配置消息类型时,过滤器放行
        if (Objects.isNull(msgTypes)) {
            chain.doFilter(purchaseMessage);
        } else {
            for (int i = 0; i < msgTypes.length; i++) {
                //匹配任一消息类型,过滤器放行
                if (Objects.equals(msgTypes[i], purchaseMessage.getMsgType())) {
                    chain.doFilter(purchaseMessage);
                    break;
                }
            }
        }
    }
}
